﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.Model;
using emp.IDAL;
using emp.BLL;
using emp.ProcessFlow;
using emp.Model.SysManage;

public partial class Task_Schedule_Task_Schedule_SetupAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TaskBasic tb = new TaskBasic();
            IList list = tb.getTask_Basic();
            TaskBasicInfo cellInfo = null;
            int m = list.Count;
            IEnumerator enumerator1 = list.GetEnumerator();
            enumerator1.MoveNext();
            int n;
            for (n = 1; n <= m; n++)
            {
                cellInfo = (TaskBasicInfo)enumerator1.Current;
                this.DropDownList1.Items.Add(new ListItem(cellInfo.TBI_VALUE, cellInfo.TBI_ID.ToString()));
                enumerator1.MoveNext();
            }
        }
    }
    protected void back_click(object sender, EventArgs e)
    {
        Response.Redirect("TaskScheduleSetupList.aspx",true);
    }
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        int tsstab_id = int.Parse(this.DropDownList1.SelectedValue);
        string tbi_type = null;
        int weekday=0;
        int monthday=0;
        if (this.RadioButton1.Checked == true)
        {
            tbi_type = "D";
        }

        if (this.RadioButton2.Checked == true)
        {
            tbi_type = "W";
            if (this.RadioButton4.Checked == true)
            {
                weekday = 1;
            }
            if (this.RadioButton5.Checked == true)
            {
                weekday = 2;
            }
            if (this.RadioButton6.Checked == true)
            {
                weekday = 3;
            }
            if (this.RadioButton7.Checked == true)
            {
                weekday = 4;
            }
            if (this.RadioButton8.Checked == true)
            {
                weekday = 5;
            }
            if (this.RadioButton9.Checked == true)
            {
                weekday =6;
            }
            if (this.RadioButton10.Checked == true)
            {
                weekday = 7;
            }
        }

        if (this.RadioButton3.Checked == true)
        {
            tbi_type = "M";
            monthday = int.Parse(this.txt_day.Text);
        }
        int minute = int.Parse(this.TextBox1.Text);
        int second = int.Parse(this.TextBox2.Text);


        if (HttpContext.Current.Session["USER_KEY"] == null)
        {
            Response.Write("<script language=javascript>window.parent.parent.location.href=\"../../logon.aspx\";</script>");
            return;
        }
        int userid = ((UserInfo)Session["USER_KEY"]).UserID;

        //int userid = 7;
        string state = null;

        if (this.ch_state.Checked == true)
        {
            state = "Y";
        }
        else
        {
            state = "N";
        }
        TaskScheduleSetupInfo tssinfo = new TaskScheduleSetupInfo(tsstab_id, tbi_type, minute, second, weekday, monthday, state,userid);
        TaskScheduleSetupController tss = new TaskScheduleSetupController();
        tss.Insert(tssinfo);

    }

    protected void ch_state_CheckedChanged(object sender, EventArgs e)
    {
        if (this.ch_state.Checked == true)
        {
            int tbi_id = int.Parse(this.DropDownList1.SelectedValue);
            TaskScheduleSetup tss = new TaskScheduleSetup();
            if (tss.is_Task_One(tbi_id) > 0)
            {

                // Response.Write("<script>alert('此任务以存在一个有效的');</script>");
                this.Label1.Text = "此任务以存在一个有效的";
                this.ch_state.Checked = false;
            }
        }
    }
    protected void RadioButton2_CheckedChanged1(object sender, EventArgs e)
    {
        this.Panel1.Visible = true;
        this.panel2.Visible = false;
        this.RadioButton4.Checked = true;
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        this.Panel1.Visible = false;
        this.panel2.Visible = false;
    }
    protected void RadioButton3_CheckedChanged1(object sender, EventArgs e)
    {
        this.panel2.Visible = true;
        this.Panel1.Visible = false;
    }
}
